package lib.persistence;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManagerFactory;

import lib.exceptions.RepositoryException;
import lib.exceptions.TransactionException;

public class PersistenceMechanismGAE implements IPersistenceMechanism {

	private static PersistenceMechanismGAE singleton;
	
	private static final PersistenceManagerFactory pm = JDOHelper.getPersistenceManagerFactory("transactions-optional");

	
	public static synchronized PersistenceMechanismGAE getInstance()throws RepositoryException {

		if (singleton == null)
			singleton = new PersistenceMechanismGAE();
		return singleton;
		
	}

	@Override
	public void connect() throws RepositoryException {
	
		
	}

	@Override
	public void disconnect() throws RepositoryException {
		pm.close();
	}

	@Override
	public Object getCommunicationChannel() throws RepositoryException {
		return pm.getPersistenceManager();
	}

	@Override
	public void releaseCommunicationChannel() throws RepositoryException {
		disconnect();
		
	}

	@Override
	public void beginTransaction() throws TransactionException {
		
		
	}

	@Override
	public void commitTransaction() throws TransactionException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void rollbackTransaction() throws TransactionException {
		// TODO Auto-generated method stub
		
	}

}
